<%
// Returns the URL used to access as a live sample the code
// at a given ID.
//
// Parameters:
//
// $0   The ID of the sample's section or containing block.
// $1   The URL from which to pull the sample; if not provided,
//      the current page is assumed.

var pagePath = env.url;

if ($1 && $1.length > 0) {
    pagePath = $1;
}

wiki.ensureExistence(pagePath);
const samplePath = `${pagePath}/_sample_.${web.slugify(web.safeDecodeURIComponent($0))}.html`;

let url;
if (env.live_samples.base_url.includes('://')) {
    url = new kuma.url.URL(env.live_samples.base_url);
    url.pathname = samplePath;
} else {
    url = samplePath;
}
%>
<%= url %>
